package com.ruoyi.media.mediaPlatform.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.media.mediaPlatform.domain.vo.MediaPlatformVo;
import com.ruoyi.media.mediaPlatform.domain.bo.MediaPlatformBo;
import com.ruoyi.media.mediaPlatform.service.IMediaPlatformService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自媒体平台配置
 *
 * @author dqw
 * @date 2023-03-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/media/mediaPlatform")
public class MediaPlatformController extends BaseController {

    private final IMediaPlatformService iMediaPlatformService;

    /**
     * 查询自媒体平台配置列表
     */
//    @SaCheckPermission("media:mediaPlatform:list")
    @GetMapping("/list")
    public TableDataInfo<MediaPlatformVo> list(MediaPlatformBo bo, PageQuery pageQuery) {
        return iMediaPlatformService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出自媒体平台配置列表
     */
    @SaCheckPermission("media:mediaPlatform:export")
    @Log(title = "自媒体平台配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MediaPlatformBo bo, HttpServletResponse response) {
        List<MediaPlatformVo> list = iMediaPlatformService.queryList(bo);
        ExcelUtil.exportExcel(list, "自媒体平台配置", MediaPlatformVo.class, response);
    }

    /**
     * 获取自媒体平台配置详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("media:mediaPlatform:query")
    @GetMapping("/{id}")
    public R<MediaPlatformVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iMediaPlatformService.queryById(id));
    }


    /**
     * 修改平台开启状态
     * @param bo
     * @return
     */
    @SaCheckPermission("media:platform:edit")
    @Log(title = "平台状态", businessType = BusinessType.UPDATE)
    @PutMapping("/updatePlatformStatus")
    public R<Void> updatePlatformStatus(@RequestBody MediaPlatformBo bo) {
        return toAjax(iMediaPlatformService.updatePlatformStatus(bo));
    }


    /**
     * 新增自媒体平台配置
     */
    @SaCheckPermission("media:mediaPlatform:add")
    @Log(title = "自媒体平台配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MediaPlatformBo bo) {
        return toAjax(iMediaPlatformService.insertByBo(bo));
    }

    /**
     * 修改自媒体平台配置
     */
    @SaCheckPermission("media:mediaPlatform:edit")
    @Log(title = "自媒体平台配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MediaPlatformBo bo) {
        return toAjax(iMediaPlatformService.updateByBo(bo));
    }

    /**
     * 删除自媒体平台配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("media:mediaPlatform:remove")
    @Log(title = "自媒体平台配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iMediaPlatformService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
